<template>
  <div class="app-container">
    <!--    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
          <el-form-item label="转移危险废物名称" prop="wxfwzyName">
            <el-input
              v-model="queryParams.wxfwzyName"
              placeholder="请输入转移危险废物名称"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="种类" prop="wxfwzyZl">
            <el-input
              v-model="queryParams.wxfwzyZl"
              placeholder="请输入种类"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="危险特性" prop="wxfwzyTx">
            <el-input
              v-model="queryParams.wxfwzyTx"
              placeholder="请输入危险特性"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="类别" prop="wxfwzyLb">
            <el-input
              v-model="queryParams.wxfwzyLb"
              placeholder="请输入类别"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="数量" prop="wxfwzyNum">
            <el-input
              v-model="queryParams.wxfwzyNum"
              placeholder="请输入数量"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="包装方式" prop="wxfwzyBz">
            <el-input
              v-model="queryParams.wxfwzyBz"
              placeholder="请输入包装方式"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="外运目的" prop="wxfwzyWymd">
            <el-input
              v-model="queryParams.wxfwzyWymd"
              placeholder="请输入外运目的"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="禁忌" prop="wxfwzyJj">
            <el-input
              v-model="queryParams.wxfwzyJj"
              placeholder="请输入禁忌"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="应急措施" prop="wxfwzyYjcs">
            <el-input
              v-model="queryParams.wxfwzyYjcs"
              placeholder="请输入应急措施"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="发运人" prop="wxfwzyFy">
            <el-input
              v-model="queryParams.wxfwzyFy"
              placeholder="请输入发运人"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="承运人" prop="wxfwzyCy">
            <el-input
              v-model="queryParams.wxfwzyCy"
              placeholder="请输入承运人"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="运达地" prop="wxfwzyYdd">
            <el-input
              v-model="queryParams.wxfwzyYdd"
              placeholder="请输入运达地"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="转移时间" prop="wxfwzyTime">
            <el-input
              v-model="queryParams.wxfwzyTime"
              placeholder="请输入转移时间"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="危险废物运输单位名称" prop="wxfwzyYcEp">
            <el-input
              v-model="queryParams.wxfwzyYcEp"
              placeholder="请输入危险废物运输单位名称"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="联系人" prop="wxfwzyYcPerson">
            <el-input
              v-model="queryParams.wxfwzyYcPerson"
              placeholder="请输入联系人"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="电话" prop="wxfwzyYcPhone">
            <el-input
              v-model="queryParams.wxfwzyYcPhone"
              placeholder="请输入电话"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="危险废物接收单位名称" prop="wxfwzyJcEp">
            <el-input
              v-model="queryParams.wxfwzyJcEp"
              placeholder="请输入危险废物接收单位名称"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="联系人" prop="wxfwzyJcPerson">
            <el-input
              v-model="queryParams.wxfwzyJcPerson"
              placeholder="请输入联系人"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="电话" prop="wxfwzyJcPhone">
            <el-input
              v-model="queryParams.wxfwzyJcPhone"
              placeholder="请输入电话"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="危险废物转移联单" prop="wxfwzyLiandan">
            <el-input
              v-model="queryParams.wxfwzyLiandan"
              placeholder="请输入危险废物转移联单"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="small" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="small" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>-->

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="small"
          @click="handleAdd"
          v-hasPermi="['solidProdution:wxfwzyInfo:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="small"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['solidProdution:wxfwzyInfo:edit']"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="small"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['solidProdution:wxfwzyInfo:remove']"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="small"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['solidProdution:wxfwzyInfo:export']"
        >导出
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="small"
          :loading="exportLoading"
          @click="proint"
          v-hasPermi="['solidProdution:wxfwzyInfo:export']"
        >打印
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="wxfwzyInfoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <!--      <el-table-column label="危险废物转移信息ID" align="center" prop="wxfwzyId" />-->
      <el-table-column label="转移危险废物名称" align="center" prop="wxfwzyName"/>
      <!--      <el-table-column label="种类" align="center" prop="wxfwzyZl" />
            <el-table-column label="危险特性" align="center" prop="wxfwzyTx" />
            <el-table-column label="类别" align="center" prop="wxfwzyLb" />
            <el-table-column label="数量" align="center" prop="wxfwzyNum" />
            <el-table-column label="包装方式" align="center" prop="wxfwzyBz" />
            <el-table-column label="外运目的" align="center" prop="wxfwzyWymd" />
            <el-table-column label="禁忌" align="center" prop="wxfwzyJj" />
            <el-table-column label="应急措施" align="center" prop="wxfwzyYjcs" />-->
      <el-table-column label="发运人" align="center" prop="wxfwzyFy"/>
      <el-table-column label="承运人" align="center" prop="wxfwzyCy"/>
      <el-table-column label="运达地" align="center" prop="wxfwzyYdd"/>
      <el-table-column label="转移时间" align="center" prop="wxfwzyTime"/>
      <el-table-column label="运输单位名称" align="center" prop="wxfwzyYcEp"/>
      <el-table-column label="联系人" align="center" prop="wxfwzyYcPerson"/>
      <el-table-column label="电话" align="center" prop="wxfwzyYcPhone"/>
      <el-table-column label="接收单位名称" align="center" prop="wxfwzyJcEp"/>
      <el-table-column label="联系人" align="center" prop="wxfwzyJcPerson"/>
      <el-table-column label="电话" align="center" prop="wxfwzyJcPhone"/>
      <el-table-column label="转移联单" align="center" prop="wxfwzyLiandan"/>
      <!--      <el-table-column label="备注" align="center" prop="remark" />
            <el-table-column label="冗余字段" align="center" prop="other" />
            <el-table-column label="冗余字段" align="center" prop="otherOne" />-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="small"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['solidProdution:wxfwzyInfo:edit']"
          >修改
          </el-button>
          <el-button
            size="small"
            @click="handleDelete(scope.row)"
            v-hasPermi="['solidProdution:wxfwzyInfo:remove']"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改危险废物转移信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" append-to-body width="60%">
      <el-form ref="form" :model="form" :rules="rules" class="clearfix " label-width="140px">
        <div class="content-left" style="margin-left: 10%">
          <div class="title2"><span> </span>基本信息</div>
          <el-form-item label="转移危险废物名称" prop="wxfwzyName">
            <el-input v-model="form.wxfwzyName" placeholder="请输入转移危险废物名称"/>
          </el-form-item>
          <el-form-item label="种类" prop="wxfwzyZl">
            <el-select v-model="form.wxfwzyZl" placeholder="请选择">
              <el-option
                v-for="dict in typeOptions"
                :key="dict.dictValue"
                :label="dict.dictLabel"
                :value="dict.dictValue"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="危险特性" prop="wxfwzyTx">
            <el-select v-model="form.wxfwzyTx" placeholder="请选择">
              <el-option
                v-for="dict in typeOptions_tx"
                :key="dict.dictValue"
                :label="dict.dictLabel"
                :value="dict.dictValue"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="类别" prop="wxfwzyLb">
            <el-select v-model="form.wxfwzyLb" placeholder="请选择">
              <el-option
                v-for="dict in typeOptions_lb"
                :key="dict.dictValue"
                :label="dict.dictLabel"
                :value="dict.dictValue"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="数量" prop="wxfwzyNum" type="number">
            <el-input v-model="form.wxfwzyNum" placeholder="请输入数量"/>
          </el-form-item>
          <el-form-item label="包装方式" prop="wxfwzyBz">
            <el-input v-model="form.wxfwzyBz" placeholder="请输入包装方式"/>
          </el-form-item>
          <el-form-item label="外运目的" prop="wxfwzyWymd">
            <el-input v-model="form.wxfwzyWymd" placeholder="请输入外运目的"/>
          </el-form-item>
          <el-form-item label="禁忌" prop="wxfwzyJj">
            <el-input v-model="form.wxfwzyJj" placeholder="请输入禁忌"/>
          </el-form-item>
          <el-form-item label="应急措施" prop="wxfwzyYjcs">
            <el-input v-model="form.wxfwzyYjcs" placeholder="请输入应急措施"/>
          </el-form-item>
        </div>
        <div class="content-middle" style="margin-left: 15%">
          <div class="title2"><span> </span>转移信息</div>
          <el-form-item label="发运人" prop="wxfwzyFy">
            <el-input v-model="form.wxfwzyFy" placeholder="请输入发运人"/>
          </el-form-item>
          <el-form-item label="承运人" prop="wxfwzyCy">
            <el-input v-model="form.wxfwzyCy" placeholder="请输入承运人"/>
          </el-form-item>
          <el-form-item label="运达地" prop="wxfwzyYdd">
            <el-input v-model="form.wxfwzyYdd" placeholder="请输入运达地"/>
          </el-form-item>
          <el-form-item label="转移时间" prop="wxfwzyTime">
            <el-date-picker v-model="form.wxfwzyTime" clearable
                            placeholder="选择转移时间"
                            size="small"
                            style="width:100%"
                            type="date"
                            value-format="yyyy-MM-dd">
            </el-date-picker>
          </el-form-item>

          <el-form-item label="运输单位名称" prop="wxfwzyYcEp">
            <el-input v-model="form.wxfwzyYcEp" placeholder="请输入危险废物运输单位名称"/>
          </el-form-item>
          <el-form-item label="联系人" prop="wxfwzyYcPerson">
            <el-input v-model="form.wxfwzyYcPerson" placeholder="请输入联系人"/>
          </el-form-item>
          <el-form-item label="电话" prop="wxfwzyYcPhone">
            <el-input v-model="form.wxfwzyYcPhone" placeholder="请输入电话"/>
          </el-form-item>
          <el-form-item label="接收单位名称" prop="wxfwzyJcEp">
            <el-input v-model="form.wxfwzyJcEp" placeholder="请输入危险废物接收单位名称"/>
          </el-form-item>
          <el-form-item label="联系人" prop="wxfwzyJcPerson">
            <el-input v-model="form.wxfwzyJcPerson" placeholder="请输入联系人"/>
          </el-form-item>
          <el-form-item label="电话" prop="wxfwzyJcPhone">
            <el-input v-model="form.wxfwzyJcPhone" placeholder="请输入电话"/>
          </el-form-item>
          <el-form-item label="转移联单" prop="wxfwzyLiandan">
            <FileUpload v-model="form.wxfwzyLiandan" />
          </el-form-item>
        </div>
        <!--        <el-form-item label="删除标志" prop="delFlag">
                  <el-input v-model="form.delFlag" placeholder="请输入删除标志" />
                </el-form-item>
                <el-form-item label="备注" prop="remark">
                  <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
                </el-form-item>
                <el-form-item label="冗余字段" prop="other">
                  <el-input v-model="form.other" type="textarea" placeholder="请输入内容" />
                </el-form-item>
                <el-form-item label="冗余字段" prop="otherOne">
                  <el-input v-model="form.otherOne" type="textarea" placeholder="请输入内容" />
                </el-form-item>-->
      </el-form>
      <div slot="footer" class="dialog-footer tianjie_button" style="text-align: center; margin-top:30px">
        <el-button type="primary" @click="submitForm" >确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  addWxfwzyInfo,
  delWxfwzyInfo,
  exportWxfwzyInfo,
  getWxfwzyInfo,
  listWxfwzyInfo,
  updateWxfwzyInfo
} from "@/api/solidProdution/wxfwzyInfo";
import {validatetoTwoPoint,validatePhoneTwo,validateIdNo,validateEMail} from "@/api/validate/validate";


export default {
  name: "WxfwzyInfo",
  data() {
    return {
      selectContent:"",
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 危险废物转移信息表格数据
      wxfwzyInfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        wxfwzyName: null,
        wxfwzyZl: null,
        wxfwzyTx: null,
        wxfwzyLb: null,
        wxfwzyNum: null,
        wxfwzyBz: null,
        wxfwzyWymd: null,
        wxfwzyJj: null,
        wxfwzyYjcs: null,
        wxfwzyFy: null,
        wxfwzyCy: null,
        wxfwzyYdd: null,
        wxfwzyTime: null,
        wxfwzyYcEp: null,
        wxfwzyYcPerson: null,
        wxfwzyYcPhone: null,
        wxfwzyJcEp: null,
        wxfwzyJcPerson: null,
        wxfwzyJcPhone: null,
        wxfwzyLiandan: null,
        other: null,
        otherOne: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        wxfwzyName: [
          {required: true, message: "企业名称不能为空", trigger: "blur"}
        ],
        wxfwzyYcPerson: [
          {required: true, message: "运输人不能为空", trigger: "blur"}
        ],
        wxfwzyYcPhone: [
          {required: true,validator:validatePhoneTwo, trigger: "blur"}
        ],
        wxfwzyJcPerson: [
          {required: true, message: "接收人不能为空", trigger: "blur"}
        ],
        wxfwzyJcPhone: [
          {required: true,validator:validatePhoneTwo, trigger: "blur"}
        ],
        wxfwzyLiandan: [
          {required: true,message: "请上传五联单",trigger: "blur"}
        ],
      },
      typeOptions:[],
      typeOptions_tx:[],
      typeOptions_lb:[],
    };
  },
  created() {
    this.getDicts("wxfwxt").then(response => {
      this.typeOptions = response.data;
    });
    this.getDicts("wxtx").then(response => {
      this.typeOptions_tx = response.data;
    });
    this.getDicts("wxfwlb").then(response => {
      this.typeOptions_lb = response.data;
    });
    this.getList();
  },
  methods: {
    proint(){
      this.$router.push({path:'/dayin',query: { content:JSON.stringify(this.selectContent)}
      })
    },
    typeFormat(row, column) {
      return this.selectDictLabel(this.typeOptions, row.wxfwzyZl);
    },
    typeFormat_tx(row, column) {
      return this.selectDictLabel(this.typeOptions_tx, row.wxfwzyTx);
    },
    typeFormat_lb(row, column) {
      return this.selectDictLabel(this.typeOptions_lb, row.wxfwzyLb);
    },
    /** 查询危险废物转移信息列表 */
    getList() {
      this.loading = true;
      listWxfwzyInfo(this.queryParams).then(response => {
         console.log(  this.wxfwzyInfoList)
        this.wxfwzyInfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        wxfwzyId: null,
        wxfwzyName: null,
        wxfwzyZl: null,
        wxfwzyTx: null,
        wxfwzyLb: null,
        wxfwzyNum: null,
        wxfwzyBz: null,
        wxfwzyWymd: null,
        wxfwzyJj: null,
        wxfwzyYjcs: null,
        wxfwzyFy: null,
        wxfwzyCy: null,
        wxfwzyYdd: null,
        wxfwzyTime: null,
        wxfwzyYcEp: null,
        wxfwzyYcPerson: null,
        wxfwzyYcPhone: null,
        wxfwzyJcEp: null,
        wxfwzyJcPerson: null,
        wxfwzyJcPhone: null,
        wxfwzyLiandan: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        other: null,
        otherOne: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
        this.selectContent=selection
      this.ids = selection.map(item => item.wxfwzyId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加危险废物转移信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const wxfwzyId = row.wxfwzyId || this.ids
      getWxfwzyInfo(wxfwzyId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改危险废物转移信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.wxfwzyId != null) {
            updateWxfwzyInfo(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addWxfwzyInfo(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const wxfwzyIds = row.wxfwzyId || this.ids;
      this.$confirm('是否确认删除危险废物转移信息编号为"' + wxfwzyIds + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        return delWxfwzyInfo(wxfwzyIds);
      }).then(() => {
        this.getList();
        this.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有危险废物转移信息数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        this.exportLoading = true;
        return exportWxfwzyInfo(queryParams);
      }).then(response => {
        this.download(response.msg);
        this.exportLoading = false;
      }).catch(() => {
      });
    }
  }
};
</script>
